package com.ambulance.utils;

import com.google.common.collect.Lists;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

/**
 * @author ：dongbl
 * @version ：
 * @Description：
 * @date ：9:19 2017/11/14
 */
public class ShellUtils
{


	public static List<String> doRun(String bashCommand)
	{
		List<String> result = Lists.newArrayList();
		BufferedReader reader = null;
		try
		{

//			String bashCommand = "sh " + "/usr/local/java/jdk1.8.0_121/lib/stopffmpeg.sh" + " ffmpeg " + ip;
//            String bashCommand = "chmod 777 " + "/usr/local/java/jdk1.8.0_121/lib/stopffmpeg.sh" ;
//            String bashCommand = "kill -9" + ip;
			System.out.println(bashCommand);
			Runtime runtime = Runtime.getRuntime();
			Process pro = runtime.exec(bashCommand);
			runtime.exec(new String[] {"source /test.sh","-c","39"},null,null);
			int status = pro.waitFor();
			if (status != 0)
			{
				System.out.println("Failed to call shell's command ");
			}

			BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream()));
			String line;
			while ((line = br.readLine()) != null)
			{
				result.add(line);
			}

			System.out.printf("输出结果:%s%n",result);

		} catch (IOException ec)
		{
			ec.printStackTrace();
		} catch (InterruptedException ex)
		{
			ex.printStackTrace();

		}

		return result;
	}
}
